<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <title>新墨</title>
    <link rel="stylesheet" href="/libs/bootstrap/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="/css/index.css?v=2017030316" type="text/css">

    <style>
        .red {
            color: #ff0000;
        }
        .form-horizontal .form-group {
            margin-right: 0;
            margin-left: 0;
        }
    </style>
</head>

<body>

<!-- 内容 -->
<div class="global-content">
    <!-- 左主导航 -->

    <aside class="app-sidebar"{{ isset($dashboard) ? '' : ' style=width:100px;' }}>

            <!-- 左导航 -->
            <div class="app-first-sidebar">
                <div>

                    <a class="team-logo-wrap" href="javascript:void (0);">
                        <div class="team-logo">
                        </div>
                    </a>

                    <nav>
                        <ul class="clearfix">
                            @foreach($permission_group as $group)
                                @if ($group['active'] == 1)
                                    <li class="active" id="dashboard-{{ $group['id'] }}">
                                @else
                                <li id="dashboard-{{ $group['id'] }}">
                                    @endif
                                    <a href="/admin/dashboard/{{ $group['id'] }}">
                                        {{--<span><img src="{{ $group['icon'] }}"></span>--}}
                                        <span>{{ $group['name'] }}</span>
                                    </a>
                                </li>
                            @endforeach
                        </ul>
                    </nav>
                </div>
            </div>

            <!-- 左底导航弹层 -->
            <div class="app-user-info">
                <span class="user-name">{{$user_name}}</span>
                <div class="user-dropdown">
                    <div class="user-dropdown-meta">
                        <div>{{$user_name}}</div>
                        <div>{{$mobile}}</div>
                    </div>
                    <div class="user-dropdown-select">
                        <a href="javascript:User.openEditPwd(1);">修改密码</a>
                        <a href="/admin/logout?redirect_url=/admin">退出</a>
                    </div>
                </div>
            </div>

            @if (isset($dashboard))
                <!-- 右导航 -->
                <div class="app-second-sidebar">
                    <div>

                        <div class="second-sidebar-title">
                            {{$dashboard}}
                        </div>
                        <nav id="js-app-second-sidebar">
                            <ul>
                                @foreach($menus as $menu)
                                    @if ($menu['active'])
                                        <li class="active">
                                    @else
                                    <li>
                                        @endif
                                        <a href="/{{ $menu['link'] }}"  title="{{$menu['name']}}" target="main-frame">{{ $menu['name'] }}</a>
                                    </li>
                                @endforeach
                            </ul>
                        </nav>
                    </div>
                </div>
            @endif

        </aside>

    <!-- 详情内容 -->
    <div class="container"{{ isset($dashboard) ? '' : ' style=margin-left:100px;' }}>
        <iframe frameborder="0"  id="main-frame" name="main-frame" src="{{$default_url}}" width="100%" height="100%" ></iframe>
    </div>

</div>

</body>
<script src="/libs/jquery/jquery-2.2.2.min.js"></script>
<script src="/libs/layer/layer.js"></script>
<script src="/libs/ebsig/base.js?v=20170206"></script>

<script>

    $(function() {

        var wh = $(window).height();
        $('.container').css('height', $(window).height() + 'px');

        //二级菜单
        var second_sidebar_obj = $('#js-app-second-sidebar').find('li');
        second_sidebar_obj.click(function () {
            second_sidebar_obj.removeClass('active').eq($(this).index()).addClass('active');
        });

    });

    var User = {

        goLogout: function () {
            window.location.href = '/admin/logout';
        },

        openEditPwd: function (flg) {

            var html = '';

            html += '<form id="edit-pwd-form" onsubmit="return false;" class="form-horizontal" role="form" style="margin-top: 20px;">';

            if (flg == 0) {
                html += '<div class="alert alert-info" role="alert" style="margin: 0 10px 20px 10px;">首次登陆必须修改密码</div>';
            }

            html += '<div class="form-group">';
            html += '<label class="col-sm-3 control-label" for="oldPwd"><span class="red pr5">*</span>&ensp;旧密码：</label>';
            html += '<div class="col-sm-6">';
            html += '<input type="password" class="form-control" name="oldPwd" id="oldPwd" placeholder="请输入旧密码">';
            html += '</div>';
            html += '</div>';

            html += '<div class="form-group">';
            html += '<label class="col-sm-3 control-label" for="newPwd"><span class="red pr5">*</span>&ensp;新密码：</label>';
            html += '<div class="col-sm-6">';
            html += '<input type="password" class="form-control" name="newPwd" id="newPwd" placeholder="请输入新密码">';
            html += '</div>';
            html += '</div>';

            html += '<div class="form-group">';
            html += '<label class="col-sm-3 control-label" for="confirmPwd"><span class="red pr5">*</span>&ensp;确认新密码：</label>';
            html += '<div class="col-sm-6">';
            html += '<input type="password" class="form-control" name="confirmPwd" id="confirmPwd" placeholder="请再次输入新密码">';
            html += '</div>';
            html += '</div>';

            html += '</form>';

            layer.open({
                title: '修改密码' ,
                offset: '70px',
                type: 1 ,
                area: ['500px', '330px'] ,
                scrollbar: false,
                closeBtn: flg,
                content: html,
                btn: ['提交'],
                yes: function () {

                    var dt = E.getFormValues('edit-pwd-form');

                    if (E.isEmpty(dt.oldPwd)) {
                        layer.alert('请输入旧密码', {icon: 2, offset: '70px'});
                        return false;
                    }

                    if (!E.isPwd(dt.newPwd)) {
                        layer.alert('请输入新的密码', {icon: 2, offset: '70px'});
                        return false;
                    }

                    if (dt.oldPwd == dt.newPwd) {
                        layer.alert('新密码不能和旧密码相同', {icon: 2, offset: '70px'});
                        return false;
                    }

                    if (dt.newPwd == '12345678' ) {
                        layer.alert('密码不能为12345678', {icon: 2, offset: '70px'});
                        return false;
                    }

                    if(dt.newPwd != dt.confirmPwd ){
                        layer.alert('两次输入的新密码不一致', {icon: 2, offset: '70px'});
                        return false;
                    }

                    $.ajax({
                        type: 'POST',
                        url:'/admin/usr/change/pwd',
                        data: dt,
                        success:function(res) {
                            if( res.code == 200 ){
                                layer.alert('密码修改成功，请重新登录', {icon: 1, offset: '70px', time: 1500 }, function () {
                                    User.goLogout();
                                });
                                setTimeout(function () {
                                    User.goLogout();
                                }, 1400);
                            }else{
                                layer.alert( res.message, {icon: 2, offset: '70px'});
                            }
                        }
                    });

                }
            });
        }

    };

    @if ($pwdFlg == 0)
    User.openEditPwd(0);
    @endif

</script>

</html>